# remap Ctrl-b to Ctrl-a
set-option -g prefix C-a
set-option -g prefix2 None

# set vim-like copy mode
setw -g mode-keys vi
bind -n F2 copy-mode
bind-key -Tcopy-mode-vi 'v' send -X begin-selection
bind-key -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel "xclip -selection clipboard -i"
bind-key -Tcopy-mode-vi 'C-V' send -X rectangle-toggle
unbind p
bind p run-shell "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"

# key bindings for moving over panes
# binding to arrows for normal people
bind-key -n M-Left select-pane -L
bind-key -n M-Right select-pane -R
bind-key -n M-Up select-pane -U
bind-key -n M-Down select-pane -D
# binded to yuio for vim people
bind-key -n M-y select-pane -L
bind-key -n M-o select-pane -R
bind-key -n M-i select-pane -U
bind-key -n M-u select-pane -D

# the new key bindings for splitting, CTRL-9 ( like CTRL-( ) for vertical, CTRL-0 ( like CTRL-) ) for horizontal
bind -n C-9 split-window -v -c "#{pane_current_path}"
bind -n C-0 split-window -h -c "#{pane_current_path}"

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"

# new window
bind -n C-t new-window -a -c "#{pane_current_path}"

# next pane
bind -n M-u next
bind -n S-Right next

# previous pane
bind -n M-i prev
bind -n S-Left prev

# make delay shorter
set -sg escape-time 0

# Toggle synchronize-panes with ^S m
bind s \
    set synchronize-panes \;\
    display "Sync #{?synchronize-panes,ON,OFF}"

set-option -g assume-paste-time 1
set-option -g default-command ""
set-option -g destroy-unattached off
set-option -g detach-on-destroy on
set-option -g display-panes-active-colour red
set-option -g display-panes-colour blue
set-option -g display-panes-time 1000
set-option -g display-time 750
set-option -g history-limit 5000
set-option -g key-table "root"
set-option -g lock-after-time 0
set-option -g lock-command "lock -np"
set-option -g message-command-style fg=yellow,bg=black
set-option -g message-style fg=black,bg=yellow
set-option -g renumber-windows on
set-option -g repeat-time 500
set-option -g set-titles off
set-option -g set-titles-string "#S:#I:#W - "#T" #{session_alerts}"
set-option -g status on
set-option -g status-interval 15
set-option -g status-justify left
set-option -g status-keys vi
set-option -g status-left "[#S] "
set-option -g status-left-length 10
set-option -g status-left-style default
set-option -g status-position bottom
set -g status-right '#[fg=colour15,bg=colour241,bold] %d/%m #[fg=colour15,bg=colour245,bold] %H:%M:%S #[fg=colour15,bg=colour241,bold] #H '
set-option -g status-right-length 40
set-option -g status-right-style default
set-option -g status-style fg=black,bg=white
setw -g window-status-current-format '#[fg=white,bg=colour241,bold] #I#[fg=white,bg=colour241,bold]:#[fg=white,bg=colour241,bold]#W '
set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-option -g word-separators " -_@"
set-option -g aggressive-resize on
set-window-option -g allow-rename off
set-window-option -g automatic-rename off

# Info on left (I don't have a session display for now)
set -g status-left ''

# quiet
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-window-option -g monitor-activity off
set-option -g bell-action none

set -g default-terminal "screen-256color"

bind-key k menu -x R -t 0 "-T Kill the session?" "Select this menu item and hit enter!" 9 'split-window; send-keys "sleep 1; pwd >> /tmp/tmux_restore_path.txt; tmux list-panes -s -F \"#\{pane_pid\} #\{pane_current_command\}\" | grep -v tmux | cut -d\" \" -f1 | while read in; do killProcessRecursive \$in; done" C-m exit C-m'

